package br.ufal.tci.nexos.arcolive.service.broker.command;

import br.ufal.tci.nexos.arcolive.ArCoLIVEServiceManager;
import br.ufal.tci.nexos.arcolive.command.ArCoLIVEClientCommand;
import br.ufal.tci.nexos.arcolive.command.ArCoLIVECommandResult;
import br.ufal.tci.nexos.arcolive.descriptors.ServiceDescriptor;
import br.ufal.tci.nexos.arcolive.service.connection.ConnectionRequest;

public class GetAvailableServicesCommand extends ArCoLIVEClientCommand {
	
	public GetAvailableServicesCommand(ConnectionRequest request) {
		super(request);
	}
	
	public ArCoLIVECommandResult executeImpl() {
		String response = "";	
		
		ServiceDescriptor serviceDescriptors[] = ArCoLIVEServiceManager.getInstance().getServiceDescriptors();
		
		for (int i = 0; i < serviceDescriptors.length; i++) {
			response = response + serviceDescriptors[i].getServiceId() + "%" + serviceDescriptors[i].getService().getName() + ",";
		}

		if (response.length() > 0) {
			response = response.substring(0, response.length()-1);
		}
			
		return new ArCoLIVECommandResult(this, response);
	}

}